using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;
using System;

namespace IQIGame.Onigao.GamePlay
{
    public class UINetTip : UIBaseWindow
    {
        /// <summary>
        /// 静态配置
        /// </summary>
        private static UICreateConfig _createConfig = new()
        {
            prefabName = nameof(UINetTip),
            layer = EUILayer.NetTip,
        };

        /// <summary>
        /// 创建UI的配置
        /// </summary>
        public override IUICreateConfig createConfig => _createConfig;

        #region Template Generate,don't modify
        protected partial class UIB_UINetTip
        {
            #region ObjectBinding Generate 
            public IQIGame.Onigao.Framework.ExButton btnCancel { protected set; get; }
            public IQIGame.Onigao.Framework.ExButton btnConnect { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textContent { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btnCancel", out var __tbv0);
                this.btnCancel = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btnConnect", out var __tbv1);
                this.btnConnect = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textContent", out var __tbv2);
                this.textContent = __tbv2;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        protected UIB_UINetTip ui { get; set; }

        private UD_NetTip uiData => _data as UD_NetTip;

        protected override void BeforeInit()
        {
            ui = new UIB_UINetTip();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.ui.btnConnect.AddClickEvent(OnClickBtnConnect);
            this.ui.btnCancel.AddClickEvent(OnClickBtnCancel);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }


        protected override void OnShow(UIBaseData data)
        {
            this.ui.textContent.text = uiData.content;
            this.ui.btnConnect.SetActive(uiData.connectAction != null);
        }

        private void OnClickBtnConnect()
        {
            Action connectAction = uiData?.connectAction;
            Close();
            connectAction?.Invoke();
        }

        private void OnClickBtnCancel()
        {
            Action cancelAction = uiData?.cancelAction;
            Close();
            cancelAction?.Invoke();
        }

        protected override void OnDispose()
        {

        }

    }
}
